<?php
require_once ($INCLUDE_PATH . "/include/WebService2Db.php");
class CheckFun {

    public static function checkusername ($name,$min=4,$max=16) {
        if(strlen($name)<$min or strlen($name)>$max)return false;
        $preg="/^[\w\\x80-\\xff-]+$/";  //定义字符范围。
        //	echo "<textarea cols=80>$preg</textarea>";   //这行是调试用的。
        if(!preg_match($preg,$name))return false;
        if(strstr($name,'　'))return false;   //不允许有全角空格

        return true;
    }

    public static function checkuser($username)
    {
        $DB=new DB_MYSQL;
        $DB->connect();
        $table = PRE."_user";
        $where=" WHERE `account` = '".$username."'";
        $sum = $DB->count_records($table, "id", $where);
        return  $sum;
    }
    public static function checkpassword($password,$min=6,$max=32) {
        if(strlen($password)<$min or strlen($password)>$max)return false;
        $preg="/\A[\!#-&\(-\~]+\Z/";   //定义字符范围(ASCII 33-126中除掉两个引号)。
        //	echo "<textarea cols=80>$preg</textarea>";   //这行是调试用的
        if(preg_match($preg,$password))return true;
        return false;
    }
    public  function checkUserType($username) {
        $DB=new DB_MYSQL;
        $DB->connect();
        $sql="SELECT *  FROM `".PRE."_user` WHERE `account` = '".$username."'";
        $query = $DB->query_first($sql);
        return $query;
    }
    public  function checkUserId($id) {
        $DB=new DB_MYSQL;
        $DB->connect();
        $sql="SELECT *  FROM `".PRE."_user` WHERE `id` = '".$id."'";
        $query = $DB->query_first($sql);
        return $query;
    }

}

?>
